<template>
  <div>
    <van-nav-bar title="收藏商品" left-text="返回" left-arrow @click-left="back" />
       <Bg>
          <div class="CollectBox" v-for="(item, index) in lists" :key="index" @click="viewProduct(item.pid)">
              <div class="CollectBoxImg">
                  <img :src="item.smallImg" alt="" class="CollectImg">
              </div>
              <div class="CollectName">{{item.name}}</div>
              <div class="CollectENname">{{item.enname}}</div>
              <div class="Collectpire">&yen;{{item.price}}</div>
          </div>
       </Bg>
  </div>
</template>

<script>
import Bg from "../components/Bg.vue";
import "../assets/less/Collect.less"
export default {
    name: "Collect",
    components:{
        Bg,
    },
    data() {
    return {
      //地址列表数据
      lists: "",
    };
  },
     created() {
    this.getAddressListData();
  },
    methods: {
        back() {
      this.$router.go(-1);
    },
       getAddressListData() {
      let tokenString = this.$cookies.get("tokenString");

      if (!tokenString) {
        console.log("浏览器token不存在");
        return this.$router.push({ name: "Login" });
      }
      
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });

      this.axios({
        //请求方式
        method: "GET",
        url: this.baseUrl + "/findAllLike",
        params: {
          appkey: this.appkey,
          tokenString
        }
      })
        .then((res) => {
          console.log("res getAddressListData ==> ", res);
          this.$toast.clear();

           if (res.data.code === 2000) {
          this.lists = res.data.result;
        } else {
          this.$toast({
            message: res.data.msg,
            forbidClick: true,
            duration: 3000
          })
        }
        })
        .catch((err) => {
          this.$toast.clear();
          console.log("err ==> ", err);
        });
    },
    
    //查看商品详情
    viewProduct(pid) {
      this.$router.push({name: 'Detail', params: {pid}});
    },
     Nikname() {
      let tokenString = this.$cookies.get("tokenString");
      // console.log("tokenString ==> ", tokenString);

      if (!tokenString) {
        console.log("浏览器token不存在");
        return this.$router.push({ name: "Login" });
      }

      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });

      this.axios({
        //请求方式
        method: "GET",
        url: this.baseUrl + "/findAccountInfo",
        params: {
          appkey: this.appkey,
          tokenString,
        },
      })
        .then((res) => {
          console.log("res Nikname ==> ", res);
          this.$toast.clear();

          if (res.data.code == 700) {
            this.$toast({
              message: res.data.msg,
              forbidClick: true,
              duration: 3000,
            });
            return this.$router.push({ name: "Login" });
          }

          if (res.data.code === "B001") {

            this.Mineoff=res.data.result[0].nickName;
            // console.log(this.Mineoff);

          } else {
            this.$toast({
              message: res.data.msg,
              forbidClick: true,
              duration: 3000,
            });
          }
        })
        .catch((err) => {
          this.$toast.clear();
          console.log("err ==> ", err);
        });
    },
    },
}
</script>

<style>

</style>